home *** CD-ROM | disk | FTP | other *** search
- ;void delete_spc_right(strg);
- ; char *strg;
-
- EXTRN _memory_model:byte
- EXTRN _error_code:byte
-
- _TEXT SEGMENT BYTE PUBLIC 'CODE'
- ASSUME CS:_TEXT
- PUBLIC _delete_spc_right
- _delete_spc_right proc near
- pushf ;save flags
- push di ;
- mov bx,sp ;bx pts to stack
- cmp _memory_model,0 ;near or far?
- jle begin ;jump if near
- inc bx ;else add 2 to BX
- inc bx ;
- begin: cmp _memory_model,2 ;data near or far?
- jb L0 ;jump if near
- les di,ss:dword ptr[bx+6] ;ES:DI pts to Strg
- jmp short L00 ;jump ahead
- L0: mov ax,ds ;ES = DS
- mov es,ax ;
- mov di,ss:[bx+6] ;ES:DI pts to Strg
- L00: mov bl,1 ;errorcode 1 = null string
- cmp byte ptr es:[di],0 ;null string?
- jz L2 ;quit if so
- mov al,0 ;seek terminating char
- mov cx,256 ;max string size
- cld ;direction forward
- repne scasb ;go find it
- jcxz L2 ;string too long, quit
- dec di ;back to last char of string
- dec di ;
- std ;direction backward
- mov al,32 ;seek space char
- mov cx,256 ;whole string
- repe scasb ;find leftmost adjacent space
- inc bl ;errorcode 2 = no spaces found
- jcxz L2 ;quit if none found
- inc di ;forward to char after last in strg
- inc di ;
- mov byte ptr es:[di],0 ;set terminating byte
- L1: mov bl,0 ;0 = spaces found and deleted
- L2: mov _error_code,bl ;set _error_code
- pop di ;
- popf ;restore flags
- cmp _memory_model,0 ;quit
- jle quit ;
- db 0CBh ;RET far
- quit: ret ;RET near
- _delete_spc_right ENDP
- _TEXT ENDS
- END